/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ServiceController;

import com.Service.BO.TeamBO;
import com.Service.DAO.SuperDAO;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author olugbokikisemiu
 */
public class saveTeamController extends HttpServlet {

    SuperDAO team;
    TeamBO tem;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {

            team = new SuperDAO();
            tem = new TeamBO();

            String name = request.getParameter("name");
            String desc = request.getParameter("description");
            String lead = request.getParameter("leadcontact");
            String add1 = request.getParameter("addressline1");
            String add2 = request.getParameter("addressline2");
            String add3 = request.getParameter("addressline3");
            String post = request.getParameter("postcode");
            String city = request.getParameter("city");
            String count = request.getParameter("county");
            int get = Integer.parseInt(request.getParameter("country"));
            String type = request.getParameter("type");
            String full = request.getParameter("full");
            String sic = request.getParameter("sic");
            int fone = Integer.parseInt(request.getParameter("phone"));
            int fax = Integer.parseInt(request.getParameter("fax"));
            String mail = request.getParameter("email");
            String web = request.getParameter("webAdd");
            int depid = Integer.parseInt(request.getParameter("diet"));
            String active = request.getParameter("Inactive");

            tem.setName(name);
            tem.setDesc(desc);
            tem.setLead(lead);
            tem.setAddline1(add1);
            tem.setAddline2(add2);
            tem.setAddline3(add3);
            tem.setPostcode(post);
            tem.setCity(city);
            tem.setCounty(count);
            tem.getCountry().setID(get);
            tem.setTypeOfBiz(type);
            tem.setFullDesc(full);
            tem.setSicCode(sic);
            tem.setPhone(fone);
            tem.setFax(fax);
            tem.setEmail(mail);
            tem.setWebAdd(web);
            tem.getDep().setId(depid);
            if (active != null) {
                tem.setIsActive("True");
            } else {
                tem.setIsActive("False");
            }
            
            team.TeamSave(tem);
            
            RequestDispatcher req = request.getRequestDispatcher("DirectorateController");
            req.forward(request, response);


        } catch(Exception e)
        {
            e.printStackTrace();
        }finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
